package org.example.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * 3. 实现简单的注销用户功能；
 *   - 输入用户名：
 *   然后直接将该用户在数据表中删除，返回：注销成功 |  该用户不存在
 */
public class Homework3 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true", "root", "root");
        Statement statement = connection.createStatement();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要注销的用户名：");
        String username = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();
        int i = statement.executeUpdate("DELETE FROM user WHERE username='"+username+"' AND password='"+password+"'");
        if (i>0){
            System.out.println("注销成功！");
        }else {
            System.out.println("该用户不存在！");
        }
        connection.close();
    }
}
